import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA
 * Description JDK17 一些新增的特性
 * User: 王杰
 * Date: 2025-05-15
 * Time: 22:38
 */
public class Test3 {
    //

    // 密封类
    sealed class Animal permits Dog {
        public String name;
        public int age;
        public void eat() {
            System.out.println("eat() ......");
        }
    }
    non-sealed class Dog extends Animal {
        public void eat() {
            System.out.println(this.name + "正在吃狗粮......");
        }
    }

//    non-sealed class Cat extends Animal {
//        public void eat() {
//            System.out.println(this.name + "正在吃狗粮......");
//        }
//    }

//   sealed class Dog extends Animal {
//        public void eat() {
//            System.out.println(this.name + "正在吃狗粮......");
//        }
//    }

    // yield
    public static void main(String[] args) {
        String data = "two";
        int result = switch (data) {
            case "one" :yield  1;
            case  "two" :yield  2;
            default :yield  -1;
        };
        System.out.println(result);
    }
    public static void main2(String[] args) {
        String data = "two";
        int result = switch (data) {
            case "one" -> 1;
            case  "two" -> 2;
            default -> -1;
        };
        System.out.println(result);
    }
    public static void main1(String[] args) {
        String data = "one";
        int result = 0; // 接收数据的返回值
        switch (data) {
            case "one":
                result = 1;// 为 result 重新赋值
                break;
            case  "two":
                result = 2;// 为 result 重新赋值
                break;
            default:
                result = -1;// 为 result 重新赋值
        }
        System.out.println(result);
    }
}
